import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;

import java.util.HashMap;
import java.util.List;

public class Main {
    public static void main(String[] args) {
            String head = "";
            String controllerTemplate = head+"templates/controller.java";
            String mapperTemplate = head+"templates/mapper.java";
            String mapperXmlTemplate = head+"templates/mapper.xml";
            String entityTemplate =head+ "templates/entity.java";
            String serviceTemplate = head+"templates/service.java";
            String serviceImplTemplate = head+"templates/serviceImpl.java";
            HashMap<OutputFile, String> map = new HashMap<>();

            map.put(OutputFile.mapperXml, "D:\\code\\bhu\\bhu-background\\src\\main\\resources\\mappers");
            map.put(OutputFile.mapper, "D:\\code\\bhu\\bhu-background\\src\\main\\java\\com\\szpt\\mo\\bhubackground\\mapper");
            map.put(OutputFile.entity, "D:\\code\\bhu\\bhu-background\\src\\main\\java\\com\\szpt\\mo\\bhubackground\\entity");
            map.put(OutputFile.controller, "D:\\code\\bhu\\bhu-background\\src\\main\\java\\com\\szpt\\mo\\bhubackground\\controller");
            map.put(OutputFile.service, "D:\\code\\bhu\\bhu-background\\src\\main\\java\\com\\szpt\\mo\\bhubackground\\service");
            map.put(OutputFile.serviceImpl, "D:\\code\\bhu\\bhu-background\\src\\main\\java\\com\\szpt\\mo\\bhubackground\\service\\impl");

            FastAutoGenerator.create("jdbc:mysql://localhost:3306/Adopt?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false", "root", "123456")
                    .globalConfig(builder -> {
                        builder.author("mo") // 设置作者
                                .enableSwagger() // 开启 swagger 模式
                                .fileOverride(); // 覆盖已生成文件

//                            .outputDir("C:\\Users\\Root\\IdeaProjects\\psi\\ADopt\\src\\main\\java"); // 指定输出目录
                    })
                    .packageConfig(builder -> {
//                    builder.parent("com.baomidou.mybatisplus.samples.generator"); // 设置父包名
                        builder.parent("com.szpt.mo.bhubackground") // 设置父包名
//                            .moduleName("ADopt") // 设置父包模块名
                                .pathInfo(map); // 设置mapperXml生成路径
                    })
                    .templateConfig(builder -> {
                        builder.controller(controllerTemplate)
                                .mapperXml(mapperXmlTemplate)
                                .entity(entityTemplate)
                                .service(serviceTemplate)
                                .serviceImpl(serviceImplTemplate)
                                .mapper(mapperTemplate);
                    })
                    .strategyConfig(builder -> {

                        builder.controllerBuilder().enableHyphenStyle()
                                .enableRestStyle();
                        builder.entityBuilder().enableLombok();

                        //有覆盖危险请勿乱动
                        List<String> strings = List.of("tb_user");

//                    strings.add("tb_user");
                        builder.addInclude(strings);

                        //注释这行才能生成代码
//                    strings = new ArrayList<>();

//                    builder.addInclude("plans_partner"); // 设置需要生成的表名

//                    builder.addTablePrefix("t_", "c_"); // 设置过滤表前缀
                    })

                    .templateEngine(new VelocityTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
//                .templateEngine(new FreemarkerTemplateEngine())

                    .execute();

        }
}
